var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);

var type = '';
var upid = '';
function add(){
	window.location.href = "action.php?controller=category&action=add&type="+type+"&upid="+upid;
}

function edits(id){
	window.location.href = "action.php?controller=category&action=edit&type="+type+"&id="+id;
}

function deletes(id){
	if(confirm('您确定删除此分类吗？')){
		window.location.href = "action.php?controller=category&action=delete&type="+type+"&id="+id;
	}
}

var imgPlus = new Image();

/**
 * 折叠分类列表
 */
function rowClicked(obj)
{
  obj = obj.parentNode.parentNode;

  var tbl = document.getElementById("list-table");
  var lvl = parseInt(obj.className);
  var fnd = false;

  for (i = 0; i < tbl.rows.length; i++)
  {
      var row = tbl.rows[i];

      if (tbl.rows[i] == obj)
      {
          fnd = true;
      }
      else
      {
          if (fnd == true)
          {
              var cur = parseInt(row.className);
              if (cur > lvl)
              {
                  row.style.display = (row.style.display != 'none') ? 'none' : (Browser.isIE) ? 'block' : 'table-row';
              }
              else
              {
                  fnd = false;
                  break;
              }
          }
      }
  }

  for (i = 0; i < obj.cells[0].childNodes.length; i++)
  {
      var imgObj = obj.cells[0].childNodes[i];
      if (imgObj.tagName == "IMG" && imgObj.src != '/images/menu_arrow.gif')
      {
          imgObj.src = (imgObj.src == imgPlus.src) ? '/images/menu_minus.gif' : imgPlus.src;
      }
  }
}
var isselect = 0;
function CheckAll(strSection,val)
{
	var i,j;
	j = 0;
	var	colInputs = document.getElementById(strSection).getElementsByTagName("input");
	for	(i=0; i < colInputs.length; i++)
	{
		if(colInputs[i].type=='checkbox'){
			colInputs[i].checked=val;
			j++;
		}
	}
	if(val)isselect=j;
	else isselect = 0
}

function sets(obj){
	if(obj.checked)isselect++;
	else isselect--;
}
function checks(){
	if(confirm('您确定删除吗？')){
		if(isselect>0)
			return true;
		else
		   alert('请选择您要操作的项目！');
	}
	return false;
}

function checkall(form, bool) 
{

 for(var e = 0; e < form.elements.length; e++) 
 {
  	var v = form.elements[e];
  	v.checked = bool;
 }
}

function implode (glue, pieces) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // +   improved by: Itsacon (http://www.itsacon.net/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
    // *     returns 2: 'Kevin van Zonneveld'

    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {
        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {
            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
                tGlue = glue;
            }
            return retVal;
        }
    }
    else {
        return pieces;
    }
}